package com.example.venue_reservation_service.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.venue_reservation_service.domain.Device;
import com.example.venue_reservation_service.mapper.DeviceMapper;
import com.example.venue_reservation_service.service.DeviceService;
import com.example.venue_reservation_service.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/device")
@Api("设备数据管理")
@CrossOrigin
public class DeviceController {

    @Resource
    private DeviceService deviceService;

    @Resource
    private DeviceMapper deviceMapper;

    @Resource
    private  SimpMessagingTemplate messagingTemplate;

    // 获取最新设备数据
    @ApiOperation("获取最新设备数据")
    @GetMapping("/latest")
    public Result getLatestDevices() {
        return Result.ok(deviceService.getLatestDevices()).message("加载成功");
    }
//
    // 定时任务 - 每秒生成一条数据
//    @Scheduled(fixedRate = 3000)
//    public void generateAndSendDeviceData() {
//        // 生成并保存新数据
//        Device newDevice = deviceService.getOne(Wrappers.<Device>query().orderByDesc("id").last("LIMIT 1"));
//
//        // 推送新数据到前端
//        messagingTemplate.convertAndSend("/topic/devices", newDevice);
//    }
}